<?php

namespace Database\Factories;

use App\Models\RecruitCategory;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Recruit>
 */
class RecruitFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $types    = ['month', 'day', 'hour'];
        $workType = $types[array_rand($types)];
        if ($workType == 'month') {
            $minSalary = mt_rand(2000, 7000);
            $maxSalary = mt_rand(7000, 20000);
            $salaryInfo = json_encode(['work_type' => $workType, 'min_salary' => $minSalary, 'max_salary' => $maxSalary]);
        } else if ($workType == 'day') {
            $minSalary = mt_rand(100, 300);
            $maxSalary = mt_rand(300, 800);
            $salaryInfo = json_encode(['work_type' => $workType, 'min_salary' => $minSalary, 'max_salary' => $maxSalary]);
        } else if ($workType == 'hour') {
            $minSalary = mt_rand(10, 30);
            $maxSalary = mt_rand(30, 100);
            $hour = mt_rand(2, 10);
            $salaryInfo = json_encode(['work_type' => $workType, 'work_hour' => $hour,'min_salary' => $minSalary, 'max_salary' => $maxSalary]);
        }

        // 随机取一个月以内的时间
        $updatedAt = $this->faker->dateTimeThisMonth();
        // 传参为生成最大时间不超过，因为创建时间需永远比更改时间要早
        $createdAt = $this->faker->dateTimeThisMonth($updatedAt);

        return [
            'city'           => fake()->city(),
            'address'        => fake()->address(),
            'address_detail' => fake()->streetAddress(),
            'zip_code'       => fake()->postcode(),
            'recruit_desc'   => fake()->sentence(),
            'latitude'       => fake()->latitude(),
            'longitude'      => fake()->longitude(),
            'status'         => mt_rand(-2, 4),
            'salary_info'    => $salaryInfo,
            'created_at'     => $createdAt->format('Y-m-d H:i:s'),
            'updated_at'     => $updatedAt->format('Y-m-d H:i:s'),
        ];

    }
}
